<?php
/**
 * Created by PhpStorm.
 * User: 共赢岛
 * Date: 2023/12/8
 * Time: 9:51
 */

namespace App\Services\LifeCycle;


use App\Admin\Services\CarService;
use App\Models\CarPackage;
use App\Models\CarPackageCategory;
use App\Models\CarPackageType;

class PackageService
{
    public static function all($condition = [])
    {
        $package = CarPackage::where([
            'category_id' => $condition['category_id'],
            'status' => DEFAULT_STATUS_SUCCESS,
        ])->get();

        if ($package) {
            return $package;
        }

        return false;
    }

    public static function one($id)
    {
        $package = CarPackage::find($id);

        $package->pic = path2url($package->pic);
        $package->brand_title = $package->brand->title;
        $package->brand_pic = path2url($package->brand->pic);
        $package->category_title = $package->type == PACKAGE_TYPE_SALE ? $package->category->title : '售后'.$package->category->title;
        $package->cars = CarService::carJsonSwitch($package->category->car_ids);

        return $package;
    }

    public static function agreement($package_id)
    {
        return CarPackage::find($package_id, ['agreement']);
    }

    public static function packageTypeId($type)
    {
        if ($type == 1) {
            $package_id = xcwyPackageIds(); //新车无忧
        } elseif ($type == 2) {
            $package_id = jcbyPackageIds(); //基础保养
        } elseif ($type == 3) {
            $package_id = bjqPackageIds(); //基础保养
        } else {
            $package_id = 0;
        }

        return $package_id;
    }
}